home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / ansi / stdio / _rename.c next >
Encoding:
C/C++ Source or Header  |  1995-08-28  |  837 b   |  44 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdio.h>
  4. #include <errno.h>
  5. #include <go32.h>
  6. #include <dpmi.h>
  7. #include <libc/dosio.h>
  8.  
  9. int _rename(const char *old, const char *new)
  10. {
  11.   __dpmi_regs r;
  12.   int olen    = strlen(old) + 1;
  13.   int i;
  14.  
  15.   r.x.dx = __tb_offset;
  16.   r.x.di = __tb_offset + olen;
  17.   r.x.ds = r.x.es = __tb_segment;
  18.  
  19.   for (i=0; i<2; i++)
  20.   {
  21.     if(_USE_LFN)
  22.       r.x.ax = 0x7156;
  23.     else
  24.       r.h.ah = 0x56;
  25.     _put_path2(new, olen);
  26.     _put_path(old);
  27.     __dpmi_int(0x21, &r);
  28.     if(r.x.flags & 1)
  29.     {
  30.       if (r.x.ax == 5 && i == 0) /* access denied */
  31.     remove(new);         /* and try again */
  32.       else
  33.       {
  34.     errno = __doserr_to_errno(r.x.ax);
  35.     return -1;
  36.       }
  37.     }
  38.     else
  39.       break;
  40.   }
  41.   return 0;
  42. }
  43.  
  44.